'
'  Add MSOffice document Version, Revision, Last Modifier and Last Save date to filename.

Option Explicit
Dim strFname
Dim strLastAuthor , strDocVersion , strDocRev , dtLastSaveTime

strFname = "C:\Users\pauthompson\Documents\Clients\Dept of Ed\HCPSS Phase II\Sprint Meetings\HCPSS Release 2.0 Sprint 1 Status Ver 1.2.xlsx"
' strFname = "C:\Users\pauthompson\Documents\Clients\Dept of Ed\HCPSS Phase II\Sprint Meetings\HCPSS Storyboard - Sprint 1.docx"
' strFname = "C:\Users\pauthompson\Documents\Clients\Dept of Ed\HCPSS Phase II\Design Docs\HCPSS Phase II.vsdx"

dim objOfficeApp
Set objOfficeApp = CreateObject("Office.Application")


Call GetExcelProps(strFname,strLastAuthor,strDocVersion,strDocRev,dtLastSaveTime)

wscript.echo "Last author=" & strLastAuthor
wscript.echo "Document version=" & strDocVersion
wscript.echo "Revision number=" & strDocRev
wscript.echo "Last save time=" & dtLastSaveTime & " == " &  IsoTime(dtLastSaveTime)


' On Error Resume Next

Sub GetExcelProps(str_Fname,vnt_LastAuthor,vnt_DocVersion,vnt_DocRev,vnt_LastSaveTime)

   Dim obj_Excel ,obj_Workbook
   Set obj_Excel = CreateObject("Excel.Application")
   obj_Excel.Visible = False
   Set obj_Workbook = obj_Excel.Workbooks.Open(str_Fname)

   vnt_LastAuthor = obj_Workbook.BuiltInDocumentProperties("Last Author").Value
   vnt_DocVersion = obj_Workbook.BuiltInDocumentProperties("Document version").Value
   vnt_DocRev = obj_Workbook.BuiltInDocumentProperties("Revision number").Value
   vnt_LastSaveTime = obj_Workbook.BuiltInDocumentProperties("Last save time").Value

   ' Cleanup, close everything and quit.
   obj_Workbook.Close
   obj_Excel.Quit
   Set obj_Workbook = Nothing
   Set obj_Excel = Nothing
End Sub



WScript.Quit


' Word:
' Last saved by
'Revision number
'Version number
'Date last saved


Function IsoTime(dt)
   If IsDate(dt) Then
      IsoTime = CStr(Year(dt)) & ZeroPad(Month(dt),2) & ZeroPad(Day(dt),2) & ZeroPad(Hour(dt),2) & ZeroPad(Minute(dt),2)
   Else
      IsoTime = "000000000000"
   End If
End Function

Function ZeroPad(vnt,n_Len)
   ZeroPad = Trim(CStr(vnt))
   While Len(ZeroPad) < n_Len
      ZeroPad = "0" & ZeroPad
   Wend
End Function

Function UserInitials(str)

End Function
